﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BlondeHeaven.DB.Model;
using BlondeHeaven.DTO;
using BlondeHeaven.UI.Models;
using Microsoft.AspNetCore.Mvc;

namespace BlondeHeaven.UI.Controllers
{
    public class PersonalController : Controller
    {
        private IDTUserService _db;

        public PersonalController(IDTUserService db)
        {
            _db = db;
        }
        public IActionResult Index()
        {
            return View();
        }



        [HttpGet]
        public IActionResult ChanggePassWord()
        {
            return View();
        }

        [HttpPost]
        public IActionResult ChanggePassWord(PersonalUserViewModel personalUserViewModel)
        {
            if (ModelState.IsValid)
            {
                User user = new User()
                {
                    Phone = personalUserViewModel.Phone,
                    PassWrod = personalUserViewModel.ChangePassword
                };
                if (personalUserViewModel.ChangePassword == personalUserViewModel.ConfirmChangePassWord)
                {
                    _db.ChangePassword(user.Phone, user.PassWrod);
                }
                else
                {
                    ModelState.AddModelError("", "两次密码不一致密码错误");
                }
            }
            return View();
        }

        [HttpGet]
        public IActionResult ChangeUserInformation()
        {
            return View();
        }
        [HttpPost]
        public IActionResult ChangeUserInformation(PersonalUserViewModel personalUserViewModel)
        { 
                User user = new User()
                {
                    Phone = personalUserViewModel.Phone,
                    Name= personalUserViewModel.Name,
                    Address= personalUserViewModel.Address,
                    Sex= personalUserViewModel.Sex,
                    Age= personalUserViewModel.Age,
                    Photo= personalUserViewModel.Photo
                };
                _db.ChangeUserInformation(user);
             
            return View();
        }
    }
}
